{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Rectangle Overlap"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #geometry #math"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #几何 #数学"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: isRectangleOverlap"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #矩形重叠"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>矩形以列表 <code>[x1, y1, x2, y2]</code> 的形式表示，其中 <code>(x1, y1)</code> 为左下角的坐标，<code>(x2, y2)</code> 是右上角的坐标。矩形的上下边平行于 x 轴，左右边平行于 y 轴。</p>\n",
    "\n",
    "<p>如果相交的面积为 <strong>正</strong> ，则称两矩形重叠。需要明确的是，只在角或边接触的两个矩形不构成重叠。</p>\n",
    "\n",
    "<p>给出两个矩形 <code>rec1</code> 和 <code>rec2</code> 。如果它们重叠，返回 <code>true</code>；否则，返回 <code>false</code> 。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>rec1 = [0,0,2,2], rec2 = [1,1,3,3]\n",
    "<strong>输出：</strong>true\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>rec1 = [0,0,1,1], rec2 = [1,0,2,1]\n",
    "<strong>输出：</strong>false\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 3：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>rec1 = [0,0,1,1], rec2 = [2,2,3,3]\n",
    "<strong>输出：</strong>false\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>rect1.length == 4</code></li>\n",
    "\t<li><code>rect2.length == 4</code></li>\n",
    "\t<li><code>-10<sup>9</sup> &lt;= rec1[i], rec2[i] &lt;= 10<sup>9</sup></code></li>\n",
    "\t<li><code>rec1</code> 和 <code>rec2</code> 表示一个面积不为零的有效矩形</li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [rectangle-overlap](https://leetcode.cn/problems/rectangle-overlap/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [rectangle-overlap](https://leetcode.cn/problems/rectangle-overlap/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['[0,0,2,2]\\n[1,1,3,3]', '[0,0,1,1]\\n[1,0,2,1]', '[0,0,1,1]\\n[2,2,3,3]']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        if rec1[2]<=rec2[0] or rec2[2]<=rec1[0] or rec1[3]<=rec2[1] or rec2[3]<=rec1[1]:\n",
    "            return False\n",
    "        return True\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        if rec1[2]<=rec2[0] or rec1[3]<=rec2[1] or rec2[2]<=rec1[0] or rec2[3]<=rec1[1]:\n",
    "            return False        \n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        #area1 = (rec1[2]-rec1[0])*(rec1[3]-rec1[1])\n",
    "        #area2 = (rec2[2]-rec2[0])*(rec2[3]-rec2[1])\n",
    "        interwidth = min(rec1[2],rec2[2]) - max(rec1[0],rec2[0])\n",
    "        interheight = min(rec1[3], rec2[3]) - max(rec1[1], rec2[1])\n",
    "        interarea = max(interwidth, 0) * max(interheight, 0)\n",
    "        if interarea >0:\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        if rec1[0] == rec1[2] or rec1[1] == rec1[3] or rec2[0] == rec2[2] or rec2[1] == rec2[3]:\n",
    "            return False\n",
    "        if rec1[2] <= rec2[0] or rec1[3] <= rec2[1] or rec1[1] >= rec2[3] or rec1[0] >= rec2[2]:\n",
    "            return False\n",
    "        else:\n",
    "            return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        x11,y11,x12,y12 = rec1\n",
    "        x21,y21,x22,y22 = rec2\n",
    "        if x21< x12 and x11<x22:\n",
    "            if y21<y12 and y11<y22:\n",
    "                return True\n",
    "        return False\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        x1 = max(rec1[0], rec2[0])\n",
    "        y1 = max(rec1[1], rec2[1])\n",
    "\n",
    "        x2 = min(rec1[2], rec2[2])\n",
    "        y2 = min(rec1[3], rec2[3])\n",
    "\n",
    "        if x1 < x2 and y1 < y2:\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        return rec1[0] < rec2[2] and rec1[2] > rec2[0] and rec1[1] < rec2[3] and rec1[3] > rec2[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        x1 = max(rec1[0], rec2[0])\n",
    "        y1 = max(rec1[1], rec2[1])\n",
    "        x2 = min(rec1[2], rec2[2])\n",
    "        y2 = min(rec1[3], rec2[3])\n",
    "\n",
    "        return True if x1 < x2 and y1 < y2 else False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        return not (rec1[2] <= rec2[0] or rec1[3] < rec2[1] or\n",
    "                rec1[0] >= rec2[2] or rec1[1] >= rec2[3])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        return rec1[0] < rec2[2] and rec2[0] < rec1[2] and rec1[1] < rec2[3] and rec2[1] < rec1[3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        return rec1[0] < rec2[2] and rec1[2] > rec2[0] and rec1[1] < rec2[3] and rec1[3] > rec2[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        return max(rec1[0],rec2[0]) < min(rec1[2],rec2[2]) and max(rec1[1],rec2[1]) < min(rec1[3],rec2[3])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        x_l,y_l=max(rec1[0],rec2[0]),max(rec1[1],rec2[1])\n",
    "        x_r,y_r=min(rec1[2],rec2[2]),min(rec1[3],rec2[3])\n",
    "        if x_r-x_l<=0 or y_r-y_l<=0:\n",
    "            return False\n",
    "        else:\n",
    "            return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        def intersect(p_left, p_right, q_left, q_right):\n",
    "            return min(p_right, q_right) > max(p_left, q_left)\n",
    "        return (intersect(rec1[0], rec1[2], rec2[0], rec2[2]) and\n",
    "                intersect(rec1[1], rec1[3], rec2[1], rec2[3]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        if rec1[0] == rec1[2] or rec1[1] == rec1[3] or rec2[0] == rec2[2] \\\n",
    "                or rec2[1] == rec2[3]:\n",
    "            return False\n",
    "        return not(rec1[2] <= rec2[0] or  # left\n",
    "                   rec1[3] <= rec2[1] or  # bottom\n",
    "                   rec1[0] >= rec2[2] or  # right\n",
    "                   rec1[1] >= rec2[3])    #top\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        # if rec1[0] <= rec2[0]:\n",
    "        #     if (rec2[0] < rec1[2] and rec2[1] < rec1[3]) and (rec1[0] < rec2[2] and rec1[1] < rec2[3]):\n",
    "        #         return True\n",
    "        # else:\n",
    "        #     if (rec1[0] < rec2[2] and rec1[1] < rec2[3]) and (rec2[0] < rec1[2] and rec2[1] < rec1[3]):\n",
    "        #         return True\n",
    "        # return False\n",
    "        def intersect(p_left, p_right, q_left, q_right):\n",
    "            return min(p_right, q_right) > max(p_left, q_left)\n",
    "        return (intersect(rec1[0], rec1[2], rec2[0], rec2[2]) and\n",
    "                intersect(rec1[1], rec1[3], rec2[1], rec2[3]))\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        return (min(rec1[2],rec2[2]) > max(rec1[0],rec2[0])) and (min(rec1[3],rec2[3]) > max(rec1[1],rec2[1]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        if (min(rec1[2],rec2[2]) - max(rec1[0],rec2[0]))>0 and (min(rec1[3],rec2[3]) - max(rec1[1],rec2[1]))>0:\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        if rec1[0] == rec1[2] or rec1[1] == rec1[3] or rec2[0] == rec2[2] or rec2[1] == rec2[3]:\n",
    "            return False\n",
    "        return not (rec1[2] <= rec2[0] or\n",
    "                    rec1[3] <= rec2[1] or\n",
    "                    rec1[0] >= rec2[2] or \n",
    "                    rec1[1] >= rec2[3])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        x1, y1, x2, y2 = rec1\n",
    "        x3, y3, x4, y4 = rec2\n",
    "        return not (y3 >= y2 or y4 <= y1 or x3 >= x2 or x4 <= x1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        return min(rec1[2], rec2[2]) > max(rec1[0], rec2[0]) and min(rec1[3], rec2[3]) > max(rec1[1], rec2[1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        # if rec1[0] <= rec2[0]:\n",
    "        #     if (rec2[0] < rec1[2] and rec2[1] < rec1[3]) and (rec1[0] < rec2[2] and rec1[1] < rec2[3]):\n",
    "        #         return True\n",
    "        # else:\n",
    "        #     if (rec1[0] < rec2[2] and rec1[1] < rec2[3]) and (rec2[0] < rec1[2] and rec2[1] < rec1[3]):\n",
    "        #         return True\n",
    "        # return False\n",
    "        if rec1[0] == rec1[2] or rec1[1] == rec1[3] or rec2[0] == rec2[2] or rec2[1] == rec2[3]:\n",
    "            return False\n",
    "        return not (rec1[2] <= rec2[0] or  # left\n",
    "                    rec1[3] <= rec2[1] or  # bottom\n",
    "                    rec1[0] >= rec2[2] or  # right\n",
    "                    rec1[1] >= rec2[3])    # top\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        def f(a1, b1, a2, b2):\n",
    "            if max(a1, a2) < min(b1, b2):\n",
    "                return True\n",
    "            return False\n",
    "        return f(rec1[0], rec1[2], rec2[0], rec2[2]) and f(rec1[1], rec1[3], rec2[1], rec2[3])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        return (min(rec1[2], rec2[2])-max(rec1[0], rec2[0])>0) and (min(rec1[3], rec2[3])-max(rec1[1], rec2[1])>0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\r\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\r\n",
    "        return rec1[0] < rec2[2] and rec2[0] < rec1[2] and rec1[1] < rec2[3] and rec2[1] < rec1[3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        def contain(a, b, c, d):\n",
    "            '''判断两个区间是否有交集'''\n",
    "            if c<a<d or c<b<d or a<c<b or a<d<b:\n",
    "                return True\n",
    "            if a==c or b==d:\n",
    "                return True\n",
    "            return False\n",
    "        \n",
    "        x1, y1, x2, y2 = rec1\n",
    "        x1a, y1a, x2a, y2a = rec2\n",
    "        return contain(x1, x2, x1a, x2a) and contain(y1, y2, y1a, y2a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        [x1, y1, x2, y2] = rec1\n",
    "        [x3, y3, x4, y4] = rec2\n",
    "        if x1 >= x4 or y1 >= y4 or x2 <= x3 or y2 <= y3:\n",
    "            return False\n",
    "        else:\n",
    "            return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        \n",
    "        x1 = max(rec1[0], rec2[0])\n",
    "        y1 = max(rec1[1], rec2[1])\n",
    "        x2 = min(rec1[2], rec2[2])\n",
    "        y2 = min(rec1[3], rec2[3])\n",
    "        w = x2 - x1\n",
    "        h = y2 - y1\n",
    "        if w<=0 or h<=0:\n",
    "            return False\n",
    "        else:\n",
    "            return True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        return rec1[0] < rec2[2] and rec2[0] < rec1[2] and rec1[1] < rec2[3] and rec2[1] < rec1[3]\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        m1 = ((rec1[0]+rec1[2])/2,(rec1[1]+rec1[3])/2)\n",
    "        m2 = ((rec2[0]+rec2[2])/2,(rec2[1]+rec2[3])/2)\n",
    "        dx = abs(m1[0]-m2[0])\n",
    "        dy = abs(m2[1]-m1[1])\n",
    "        if 2*dx<abs(rec1[0]-rec1[2])+abs(rec2[0]-rec2[2]) and 2*dy<abs(rec1[1]-rec1[3])+abs(rec2[1]-rec2[3]):\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        x_overlap = not(rec1[2] <= rec2[0] or rec2[2] <= rec1[0])\n",
    "        y_overlap = not(rec1[3] <= rec2[1] or rec2[3] <= rec1[1])\n",
    "        return x_overlap and y_overlap\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        if rec1[0] == rec1[2] or rec1[1] == rec1[3] or rec2[0] == rec2[2] or rec2[1] == rec2[3]:\n",
    "            return False\n",
    "        return not (rec1[2] <= rec2[0] or  # left\n",
    "                    rec1[3] <= rec2[1] or  # bottom\n",
    "                    rec1[0] >= rec2[2] or  # right\n",
    "                    rec1[1] >= rec2[3])    # top"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        if rec1[2]<=rec2[0] or rec1[3]<=rec2[1] or rec2[2]<=rec1[0] or rec2[3]<=rec1[1]:\n",
    "            return False\n",
    "        return True\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\r\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\r\n",
    "        return not (\r\n",
    "            rec1[0]>=rec2[2] or\r\n",
    "            rec1[2]<=rec2[0] or\r\n",
    "            rec1[1]>=rec2[3] or\r\n",
    "            rec1[3]<=rec2[1]\r\n",
    "        )\r\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        if rec1[0] == rec1[2] or rec1[1] == rec1[3] or rec2[0] == rec2[2] or rec2[1] == rec2[3]:\n",
    "            return False\n",
    "        return not (rec1[2] <= rec2[0] or\n",
    "                    rec1[3] <= rec2[1] or\n",
    "                    rec1[0] >= rec2[2] or \n",
    "                    rec1[1] >= rec2[3])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        def intersect(p_left, p_right, q_left, q_right):\n",
    "            return min(p_right, q_right) > max(p_left, q_left)\n",
    "        return (intersect(rec1[0], rec1[2], rec2[0], rec2[2]) and\n",
    "        intersect(rec1[1], rec1[3], rec2[1], rec2[3]))\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        if rec1[0] <= rec2[0]:\n",
    "            if (rec2[0] < rec1[2] and rec2[1] < rec1[3]) and (rec1[0] < rec2[2] and rec1[1] < rec2[3]):\n",
    "                return True\n",
    "        else:\n",
    "            if (rec1[0] < rec2[2] and rec1[1] < rec2[3]) and (rec2[0] < rec1[2] and rec2[1] < rec1[3]):\n",
    "                return True\n",
    "        return False\n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        l = []\n",
    "        r = []\n",
    "        if rec1[0] < rec2[0]:\n",
    "            l = rec1\n",
    "            r = rec2\n",
    "        else:\n",
    "            l = rec2\n",
    "            r = rec1\n",
    "        if (r[0]<l[2]<=r[2] and not(l[3]<=r[1] or l[1]>=r[3])) or (r[2]<l[2] and not((r[1]>=l[3]) or (r[3]<=l[1]))):\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        if rec1[0] <= rec2[0]:\n",
    "            if (rec2[0] < rec1[2] and rec2[1] < rec1[3]) and (rec1[0] < rec2[2] and rec1[1] < rec2[3]):\n",
    "                return True\n",
    "        else:\n",
    "            if (rec1[0] < rec2[2] and rec1[1] < rec2[3]) and (rec2[0] < rec1[2] and rec2[1] < rec1[3]):\n",
    "                return True\n",
    "        return False\n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        ax1,ay1,ax2,ay2 = rec1\n",
    "        bx1,by1,bx2,by2 = rec2\n",
    "        len1 = ax2 - ax1\n",
    "        len2 = bx2 - bx1\n",
    "\n",
    "        len3 = ay2 - ay1\n",
    "        len4 = by2 - by1\n",
    "        length2 = max(ay2,by2) - min(ay1,by1)\n",
    "        length1 = max(ax2,bx2) - min(ax1,bx1)\n",
    "        print(len1,len2,len3,len4)\n",
    "        print(length1,length2)\n",
    "        # if len1+len2 == length1 and len3 + len4 < length2:\n",
    "        #     return True\n",
    "        # if len3+len4 == length2 and len1+len2 < length1:\n",
    "        #     return True\n",
    "        if len1+len2 > length1 and len3 + len4 > length2:\n",
    "            return True\n",
    "        return False\n",
    "          \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from typing import List\r\n",
    "class Solution:\r\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\r\n",
    "        return (rec1[2] - rec2[0]) * (rec2[2] - rec1[0]) > 0 and (rec1[3] - rec2[1]) * (rec2[3] - rec1[1]) > 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        return (min(rec1[2],rec2[2]) > max(rec1[0],rec2[0])) and (min(rec1[3],rec2[3]) > max(rec1[1],rec2[1]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        x_overlap = not(rec1[2] <= rec2[0] or rec2[2] <= rec1[0])\n",
    "        y_overlap = not(rec1[3] <= rec2[1] or rec2[3] <= rec1[1])\n",
    "        return x_overlap and y_overlap"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        if rec1[0] <= rec2[0]:\n",
    "            if (rec2[0] < rec1[2] and rec2[1] < rec1[3]) and (rec1[0] < rec2[2] and rec1[1] < rec2[3]):\n",
    "                return True\n",
    "        else:\n",
    "            if (rec1[0] < rec2[2] and rec1[1] < rec2[3]) and (rec2[0] < rec1[2] and rec2[1] < rec1[3]):\n",
    "                return True\n",
    "        return False\n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        if rec1[2]<=rec2[0] or rec2[2]<=rec1[0]:\n",
    "            return False\n",
    "        if rec1[3]<=rec2[1] or rec2[3]<=rec1[1]:\n",
    "            return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        return not(rec2[0]>=rec1[2] or rec2[2]<=rec1[0] or rec2[1]>=rec1[3] or rec2[3]<=rec1[1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        return (min(rec1[2],rec2[2])>max(rec1[0],rec2[0])) and (min(rec1[3],rec2[3])>max(rec1[1],rec2[1]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        if rec1[0] == rec1[2] or rec1[1] == rec1[3] or rec2[0] == rec2[2] or rec2[1] == rec2[3]:\n",
    "            return False\n",
    "        return not (rec1[2] <= rec2[0] or  # left\n",
    "                    rec1[3] <= rec2[1] or  # bottom\n",
    "                    rec1[0] >= rec2[2] or  # right\n",
    "                    rec1[1] >= rec2[3])    # top\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        def judgeInterSect(a_left,a_right,b_left,b_right):\n",
    "            return min(a_right,b_right)>max(a_left,b_left)\n",
    "        return judgeInterSect(rec1[0],rec1[2],rec2[0],rec2[2]) and judgeInterSect(rec1[1],rec1[3],rec2[1],rec2[3])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        max_value_x = max(rec1[0],rec2[0]);\n",
    "        min_value_x = min(rec1[2],rec2[2]);\n",
    "        max_value_y = max(rec1[1],rec2[1]);\n",
    "        min_value_y = min(rec1[3],rec2[3]);\n",
    "\n",
    "        if min_value_x > max_value_x and min_value_y > max_value_y:\n",
    "            return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        if rec2[0] >= rec1[2] or rec2[1] >= rec1[3] or rec2[2] <= rec1[0] or rec2[3] <= rec1[1]:\n",
    "            # 右 上 左 下\n",
    "            return False\n",
    "        else:\n",
    "            return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1, rec2):\n",
    "        \"\"\"\n",
    "        :type rec1: List[int]\n",
    "        :type rec2: List[int]\n",
    "        :rtype: bool\n",
    "        \"\"\"\n",
    "        # 长和宽的坐标都分别相交\n",
    "        \n",
    "        x1,y1,x2,y2=rec1\n",
    "        x3,y3,x4,y4=rec2\n",
    "        return (x3-x2)*(x4-x1)<0 and (y3-y2)*(y4-y1)<0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        rec1_x1, rec1_x2 = rec1[0], rec1[2]\n",
    "        rec2_x1, rec2_x2 = rec2[0], rec2[2]\n",
    "        if rec1_x2 <= rec2_x1 or rec2_x2 <= rec1_x1:\n",
    "            return False\n",
    "        \n",
    "        rec1_x1, rec1_x2 = rec1[1], rec1[3]\n",
    "        rec2_x1, rec2_x2 = rec2[1], rec2[3]\n",
    "        if rec1_x2 <= rec2_x1 or rec2_x2 <= rec1_x1:\n",
    "            return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        if rec1[0]<rec2[2] and rec1[1]<rec2[3] and rec1[2]>rec2[0] and rec1[3]>rec2[1]:\n",
    "            return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        if rec1[0] == rec1[2] or rec1[1] == rec1[3] \\\n",
    "           or rec2[0] == rec2[2] or rec2[1] == rec2[3]:\n",
    "            return False\n",
    "        return not (rec1[2] <= rec2[0] or  \\\n",
    "                    rec1[3] <= rec2[1] or  \\\n",
    "                    rec1[0] >= rec2[2] or \\\n",
    "                    rec1[1] >= rec2[3])   \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        x1, y1, x2, y2 = rec1\n",
    "        x3, y3, x4, y4 = rec2 \n",
    "        if x1 == x2 or y1 == y2 or x3 == x4 or y3 == y4:\n",
    "            return False \n",
    "        if x1 >= x4 or x2 <= x3 or y1 >= y4 or y2 <= y3:\n",
    "            return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        a = rec1[0] >= rec2[2] or rec1[2] <= rec2[0]\n",
    "        b = rec1[1] >= rec2[3] or rec1[3] <= rec2[1]\n",
    "        c = a or b\n",
    "        return not c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "# class Solution:\n",
    "#     def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "\n",
    "\n",
    "#         def check_in(pt):\n",
    "\n",
    "#             if  rec1[0] < pt[0] <rec1[2] and rec1[1] < pt[1] <rec1[3]:\n",
    "\n",
    "#                 return True\n",
    "            \n",
    "#             return False\n",
    "\n",
    "#         # def check_parl(pt1, pt2):\n",
    "\n",
    "\n",
    "\n",
    "#         p1 = (rec2[0], rec2[1])\n",
    "#         p2 = (rec2[0], rec2[3])\n",
    "#         p3 = (rec2[2], rec2[1])\n",
    "#         p4 = (rec2[2], rec2[3])\n",
    "\n",
    "#         if check_in(p1) or check_in(p2) or check_in(p3) or check_in(p4):\n",
    "\n",
    "#             return True\n",
    "\n",
    "#         # parallel intersection ...\n",
    "\n",
    "\n",
    "\n",
    "#         # x2 - x1 == x2 - x1, check the column\n",
    "#         if rec1[2] - rec1[0] == rec2[2]-rec2[0] and (rec2[0])\n",
    "\n",
    "#         # y2- y1 == y2 - y1, check the row\n",
    "\n",
    "#         return False\n",
    "        \n",
    "\n",
    "\n",
    "\n",
    "        # # 包含关系\n",
    "\n",
    "        # if rec1[2]-rec1[0] >= rec2[2] - rec2[0] and rec1[3]-rec1[0] >= rec2[2] - rec2[0]:\n",
    "\n",
    "        #     return True\n",
    "\n",
    "        # elif rec1[2]-rec1[0] <= rec2[2] - rec2[0] and rec1[3]-rec1[0] <= rec2[2] - rec2[0]:\n",
    "\n",
    "        #     return True\n",
    "\n",
    "        \n",
    "\n",
    "\n",
    "        # # compare column with row\n",
    "\n",
    "        # width_1 = rec1[3] - rec1[1]\n",
    "\n",
    "        # height_1 = rec1[2] - rec1[0]\n",
    "\n",
    "        # width_2 = rec2[3] - rec2[1]\n",
    "\n",
    "        # height_2 = rec2[2] - rec2[0]\n",
    "\n",
    "        # if rec2[1] <= (rec1[1] + height_1) < rec2[3] and rec1[1] <=rec2[1]:\n",
    "\n",
    "        #     if rec2[0] < (rec1[0] + width_1) <=rec2[2] and rec1[0] <rec2[0]:\n",
    "\n",
    "        #         return True\n",
    "\n",
    "        #     if rec2[0] <= (rec1[0] ) <rec2[2] and rec1[2] > rec2[2]:\n",
    "\n",
    "        #         return True\n",
    "\n",
    "        # if rec2[1] <= (rec1[1]) <= rec2[3] and rec1[3] >=rec2[1]:\n",
    "\n",
    "        #     if rec2[0] < (rec1[0] + width_1) <=rec2[2] and rec1[0] <rec2[0]:\n",
    "\n",
    "        #         return True\n",
    "\n",
    "        #     if rec2[0] <= (rec1[0] ) <rec2[2] and rec1[2] > rec2[2]:\n",
    "\n",
    "        #         return True\n",
    "\n",
    "\n",
    "        # # Edge case:\n",
    "\n",
    "        # if rec2[1] <= (rec1[1]) <= rec2[3] and rec2[1] <= (rec1[3]) <= rec2[3]:\n",
    "\n",
    "        #     if rec2[0] < (rec1[0] + width_1) <=rec2[2] and rec1[0] <rec2[0]:\n",
    "\n",
    "        #         return True\n",
    "\n",
    "        #     if rec2[0] <= (rec1[0] ) <rec2[2] and rec1[2] > rec2[2]:\n",
    "\n",
    "        #         return True\n",
    "\n",
    "\n",
    "        # if rec1[1] <= (rec2[1]) <= rec1[3] and rec1[1] <= (rec2[3]) <= rec1[3]:\n",
    "\n",
    "\n",
    "        #     if rec1[0] < (rec2[0] + width_2) <=rec1[2] and rec2[0] <rec1[0]:\n",
    "\n",
    "        #         return True\n",
    "\n",
    "        #     if rec1[0] <= (rec2[0] ) <rec2[2] and rec2[2] > rec1[2]:\n",
    "\n",
    "        #         return True\n",
    "\n",
    "\n",
    "        # return False\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        def intersect(p_left, p_right, q_left, q_right):\n",
    "            return min(p_right, q_right) > max(p_left, q_left)\n",
    "        return (intersect(rec1[0], rec1[2], rec2[0], rec2[2]) and\n",
    "                intersect(rec1[1], rec1[3], rec2[1], rec2[3]))\n",
    "\n",
    "        \n",
    "\n",
    "\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\r\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\r\n",
    "        w1=rec1[2]-rec1[0]\r\n",
    "        h1=rec1[3]-rec1[1]\r\n",
    "        w2=rec2[2]-rec2[0]\r\n",
    "        h2=rec2[3]-rec2[1]\r\n",
    "        most_left=min(rec1[0],rec2[0])\r\n",
    "        most_right=max(rec1[2],rec2[2])\r\n",
    "        most_top=max(rec1[3],rec2[3])\r\n",
    "        most_bottom=min(rec1[1],rec2[1])\r\n",
    "        return w1+w2>most_right-most_left and h1+h2>most_top-most_bottom\r\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        return rec1[0] < rec2[2] and rec2[0] < rec1[2] and rec1[1] < rec2[3] and rec2[1] < rec1[3]\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        x1, y1, x2, y2 = rec1\n",
    "        x3, y3, x4, y4 = rec2\n",
    "        return not (y3 >= y2 or y4 <= y1 or x3 >= x2 or x4 <= x1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        if rec2[0] >= rec1[2] or rec2[2] <= rec1[0] or rec1[1] >= rec2[3] or rec1[3] <= rec2[1] :\n",
    "            return False\n",
    "        else:\n",
    "            return True \n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        return self.isSet([rec1[0], rec1[2]], [rec2[0], rec2[2]]) and self.isSet([rec1[1], rec1[3]], [rec2[1], rec2[3]])\n",
    "\n",
    "    def isSet(self, li1, li2):\n",
    "        if max(min(li1), min(li2)) < min(max(li1), max(li2)):\n",
    "            return True\n",
    "        else:\n",
    "            return False\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        if rec2[0]>=rec1[2] or rec2[2]<=rec1[0] or rec2[1]>=rec1[3] or rec2[3]<=rec1[1]:\n",
    "            return False\n",
    "        else:\n",
    "            return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        # 不会重叠的情况你的右上角和我的右下角不在一起，或者在同一条线上\n",
    "        if rec2[0]>=rec1[2] or rec2[2]<=rec1[0] or rec2[1]>=rec1[3] or rec2[3]<=rec1[1]:\n",
    "            return False\n",
    "        else:\n",
    "            return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        return (rec1[0]<rec2[2]and rec2[0]<rec1[2])and ((rec1[1]<rec2[3]and rec2[1]<rec1[3]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        if rec1[0] >= rec2[2] or rec1[2] <= rec2[0] or rec1[1] >= rec2[3] or rec1[3] <= rec2[1]:\n",
    "            return False\n",
    "        \n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        x1 = max(rec1[0], rec2[0])\n",
    "        y1 = max(rec1[1], rec2[1])\n",
    "\n",
    "        x2 = min(rec1[2], rec2[2])\n",
    "        y2 = min(rec1[3], rec2[3])\n",
    "\n",
    "        return x1 < x2 and y1 < y2\n",
    "       \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        a1, b1, a2, b2 = rec1\n",
    "        c1, d1, c2, d2 = rec2\n",
    "        return not (d1>=b2 or c1>=a2 or d2<=b1 or c2<=a1)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        if rec1[2]<=rec2[0] or rec2[2]<=rec1[0] or rec1[3]<=rec2[1] or rec2[3]<=rec1[1]:\n",
    "            return False\n",
    "        return True\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "# class Solution:\n",
    "#     def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "#         x1,y1=[rec1[0],rec1[2]],[rec1[1],rec1[3]]\n",
    "#         x2,y2=[rec2[0],rec2[2]],[rec2[1],rec2[3]]\n",
    "#         return x1[0]<x2[1] and x2[0]<x1[1] and y1[0]<y2[1] and y2[0]<y1[1]\n",
    "\n",
    "### 官2：\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        def intersect(p_left, p_right, q_left, q_right):\n",
    "            return min(p_right, q_right) > max(p_left, q_left)\n",
    "        return (intersect(rec1[0], rec1[2], rec2[0], rec2[2]) and\n",
    "                intersect(rec1[1], rec1[3], rec2[1], rec2[3]))\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n",
    "        left = max(rec1[0], rec2[0])\n",
    "        right = min(rec1[2], rec2[2])\n",
    "        top = max(rec1[1], rec2[1])\n",
    "        bottom = min(rec1[3], rec2[3])\n",
    "\n",
    "        if right > left and bottom > top:\n",
    "            return True\n",
    "        else:\n",
    "            return False\n",
    "\n",
    "        # 测试示例\n",
    "        print(is_overlap([0, 0, 2, 2], [1, 1, 3, 3]))  # 输出: True\n",
    "        print(is_overlap([0, 0, 1, 1], [1, 0, 2, 1]))  # 输出: False\n",
    "        print(is_overlap([0, 0, 1, 1], [2, 2, 3, 3]))  # 输出: False"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
